local scene = director:createScene()

function scene:setUp(event)
    dbg.print("sceneTime:setUp")
	
	local scaleX = 320/director.displayWidth
	local scaleY = 480/director.displayHeight
	local initialY = 370/scaleY
	labelTime = {}
	balloonTime = {}
	line = {}
	
	local file = io.open("bestTimes.txt")
		leveltimesOne = tonumber(file:read())
		leveltimesTwo = tonumber(file:read())
		leveltimesThree = tonumber(file:read())
		leveltimesFour = tonumber(file:read())
		leveltimesFive = tonumber(file:read())
		file:close()
		
	labelTimeTitle = director:createLabel({x=director.displayCenterX, y=420/scaleY, text="BEST TIMES", hAlignment="center", xAnchor=0.5, color=color.white, })
	labelTimeTitle.xScale = 1/scaleX
	labelTimeTitle.yScale = 1/scaleY
	
	for i = 1, 5 do
		initialY=initialY-60/scaleY
		balloonTime[i] = director:createSprite(director.displayCenterX, initialY ,"img/balloons.png")
		balloonTime[i].xScale=.8/scaleX 
		balloonTime[i].yScale=1/scaleY
		balloonTime[i].xAnchor = .5
		labelTime[i] = director:createLabel({x=balloonTime[i].h*3/10, y=balloonTime[i].w*3/10, text="", hAlignment="left", xAnchor=0, yAnchor=0, color=color.black, })
		balloonTime[i]:addChild(labelTime[i])
		line[i] = director:createSprite(balloonTime[i].h*5/10 ,0,"img/lineTwo.png")
		balloonTime[i]:addChild(line[i])
		line[i].xAnchor=0.5
		line[i].yAnchor=1
		line[i].zOrder = -1
		line[i].xAnchor=0.5; line[i].yAnchor=1
		line[i].xScale = .7
		line[i].yScale = .7
	end
	
	labelTime[1].text = leveltimesOne
	balloonTime[1].x =director.displayCenterX-40/scaleX
	balloonTime[1].color = color.blue
	labelTime[1].color = color.white
	labelTime[2].text = leveltimesTwo
	balloonTime[2].x =director.displayCenterX+40/scaleX
	balloonTime[2].color = color.green
	labelTime[3].text = leveltimesThree
	balloonTime[3].x =director.displayCenterX-40/scaleX
	balloonTime[3].color = color.fuchsia
	labelTime[3].color = color.white
	labelTime[4].text = leveltimesFour
	balloonTime[4].x =director.displayCenterX+40/scaleX
	balloonTime[4].color = color.yellow
	labelTime[5].text = leveltimesFive
	balloonTime[5].x =director.displayCenterX-40/scaleX
	balloonTime[5].color = color.aqua
	
	local buttonBack = director:createSprite(250/scaleX, 18/scaleY, "img/button.png")
	buttonBack.xAnchor=0.5; buttonBack.yAnchor=0.5
	buttonBack.xScale=.5/scaleX; buttonBack.yScale=.3/scaleY
	labelBack = director:createLabel(250/scaleX, 6/scaleY, "Back")
	labelBack.xAnchor=0.5;
	labelBack.zOrder = buttonBack.zOrder
	labelBack. hAlignment="center"
	labelBack.xScale = 1/scaleX
	labelBack.yScale = 1/scaleY
	
	function buttonBack:touch(event)
		if (event.phase == 'began') then
			system:sendEvent("moveToSceneMenu")
		end
	end
	buttonBack:addEventListener('touch', buttonBack)
end

function scene:tearDown(event)
    dbg.print("sceneTime:tearDown")
end

scene:addEventListener({"setUp", "tearDown"}, scene)

return scene -- We must return the scene object!